package boun.swe.bob.service;

import boun.swe.bob.dao.*;
import boun.swe.bob.entities.User;
import boun.swe.bob.util.MailSender;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;

/**
 * This controller contains the methods for DAOs
 * This controller is extended by all DAOs
 */

abstract class BaseController {

    @Autowired
    protected UserDao userDao;

    @Autowired

    protected UserMessageDao userMessageDao;

    @Autowired

    protected PublicationDao publicationDao;

    @Autowired
    protected UserTweetDao userTweetDao;

    @Autowired
    protected UserActionDao userActionDao;

    @Autowired
    protected AuthorityDao authorityDao;

    @Autowired
    protected UserInfoDao userInfoDao;

    @Autowired
    protected CompositeDao compositeDao;

    @Autowired
    protected LikesDao likesDao;

    @Autowired
    protected CommentsDao commentsDao;

    @Autowired
    protected FriendDao friendDao;

    @Autowired
    protected FriendRequestDao friendRequestDao;

    @Autowired
    protected MailSender mailSender;

    @Autowired
    protected HomeFeedDao homeFeedDao;

    @Autowired
    protected GroupDao groupDao;

    @Autowired
    protected Bob_EventDao bob_EventDao; 


    /**
     * This method is for finding if the user is admin or not
     *
     * @param httpServletRequest http request
     * @return boolean value
     */
    protected boolean isAdmin(HttpServletRequest httpServletRequest){
        String role = (String) httpServletRequest.getSession().getAttribute("ROLE");
        return "ROLE_ADMIN".equals(role);
    }

    /**
     * This method returns the role of the logged in user
     *
     * @param httpServletRequest http request
     * @return role string
     */
    protected String getRole(HttpServletRequest httpServletRequest){
        return (String) httpServletRequest.getSession().getAttribute("ROLE");   
    }

    /**
     * This method returns the user record
     *
     * @param httpServletRequest http request
     * @return user object
     */
    protected User getLoggedInUser(HttpServletRequest httpServletRequest){
        return (User) httpServletRequest.getSession().getAttribute("user");
    }

    /**
     * This method gets if the user is itself or not
     *
     * @param httpServletRequest http request
     * @return boolean value
     */
    protected boolean isHimself(HttpServletRequest httpServletRequest){
        return httpServletRequest.getParameter("wantedUserId") == null ? true : false;
    }
}
